<?php include("/includes/header.php") ?>
<?php include("/includes/sidebar.php") ?>


<?php  
	$sql_tipe_user = "SELECT tipe_user.* FROM tipe_user INNER JOIN user ON user.idtipe_user = tipe_user.id WHERE user.id = $_SESSION[idUser]";
	$query_tipe_user = mysql_query($sql_tipe_user);
	$tipe_user = mysql_fetch_array($query_tipe_user);
	if ($tipe_user[kode] == "TU-001") {
?>
<div class="header">
	<span>
		<a href="resto.php">
			<i class="fa fa-cutlery"></i> Restaurant
		</a>
	</span>
	<span>
		<a href="resto-invoice-list.php">
			<i class="fa fa-list-alt"></i> Invoice List
		</a>
	</span>
</div>

<div class="breadcumb">
	<ul>
		<li>
			<a href="resto.php">Table List</a>
		</li>
	</ul>
	<div class="clear"></div>
</div>

<?php } ?>

<div class="content row-fluid"> 
	<div class="span12 table-placer" data-table="room" data-prim-field="id">
		<div class="alert alert-info">Table List</div>
		<div class="row-fluid index-pos-placer">
			<?php  
				$sql_setting = "SELECT * FROM setting";
				$query_setting = mysql_query($sql_setting);
				$setting = mysql_fetch_array($query_setting);
				for ($i=1; $i <= $setting['jumlah_meja']; $i++) { 

					$sql_resto = "SELECT * FROM resto WHERE no_meja = '$i' ORDER BY id DESC LIMIT 1";
					$query_resto = mysql_query($sql_resto);
					if (mysql_num_rows($query_resto) > 0) {
						$query_resto = mysql_query($sql_resto);
						$result_resto = mysql_fetch_array($query_resto);

						$sql_nota = "SELECT * FROM nota WHERE idresto = '$result_resto[id]' AND is_paid = 1";
						$query_nota = mysql_query($sql_nota);
						$jumlah_nota = mysql_num_rows($query_nota);
						if ($jumlah_nota > 0) {
							$sql_resto_menu = "SELECT * FROM resto_menu WHERE idresto = '$result_resto[id]' GROUP BY bill";
							$query_resto_menu = mysql_query($sql_resto_menu);
							$jumlah_resto_menu = mysql_num_rows($query_resto_menu);
							if ($jumlah_nota == $jumlah_resto_menu) {
								$class_book = "";
							} else {
								$class_book = "booked";	
							}
						} else {
							$class_book = "booked";
						}
					} else {
						$class_book = "";
					}



					if (($i-1)%4 == 0) {
			?>
		</div>
		<div class="row-fluid index-pos-placer">
			<?php
					}
			?>
				<span class="span3 index-pos <?php echo $class_book; ?>">
					<a href="resto-trans.php?<?php echo trim(base64_encode("id"), '=')."=".base64_encode($i) ?>">
						<div>
							Meja <?php echo $i; ?>
						</div>
					</a>
				</span>
			<?php
				}
			?>
		</div>
	</div>           
</div>

<div class="footer">
</div>

<?php include("/includes/footer.php") ?>   

<script type="text/javascript">
	$(document).ready(function() {
	});
</script>        